package cn.imokay.juc.cas;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicReference;

public class AtomReferenceDemo {
    public static void main(String[] args) {
        User u3 = new User(13, "张三");
        User u4 = new User(14, "李四");
        AtomicReference<User> atomicReference = new AtomicReference<>();
        atomicReference.set(u3);
        System.out.println(atomicReference.compareAndSet(u3, u4));
        System.out.println(atomicReference.get());

        System.out.println(atomicReference.compareAndSet(u3, u4));
        System.out.println(atomicReference.get());
    }
}

@Data
@ToString
@AllArgsConstructor
class User{
    private int age;
    private String name;

}
